import com.example.springmvc.mapper.UserMapper;
import com.example.springmvc.pojo.User;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.junit.Before;
import org.junit.Test;

import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class test {
    SqlSessionFactory sqlSessionFactory;
    //注解：每次执行下面任意一个测试前都会先执行此方法
    @Before
    public void init(){
        // 1. 创建SqlSessionFactoryBuilder对象
        SqlSessionFactoryBuilder sqlSessionFactoryBuilder=new SqlSessionFactoryBuilder();
        // 2. 加载SqlMapConfig.xml配置文件
        InputStream inputStream = null;
        try {
            inputStream = Resources.getResourceAsStream("sqlMapConfig.xml");
        } catch (IOException e) {
            e.printStackTrace();
        }
        // 3. 创建SqlSessionFactory对象
        sqlSessionFactory=sqlSessionFactoryBuilder.build(inputStream);
    }

    @Test
    public void test(){
        SqlSession sqlSession = sqlSessionFactory.openSession();
        UserMapper userMapper=sqlSession.getMapper(UserMapper.class);
        List ids=new ArrayList();
        ids.add(10);
        Map map=new HashMap<>();
        map.put("username","张三");
        map.put("ids",ids);
        System.out.println(map);
        List<User> list=userMapper.selectByExample2(map);
        System.out.println(list.toString());
    }
}
